﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AlgoImpl
{
    public class WorkerStat
    {
        private string m_Worker;
        private List<string> m_RequestedShifts;
        private List<string> m_RegisteredShifts;
        private List<string> m_RequestedAndNotGet;
        private List<string> m_GetAndNotRequested;
        private double m_Rank;

        public WorkerStat(List<string> reqShifts, List<string> regShifts, string workerId)
        {
            m_Worker = workerId;
            m_RegisteredShifts = regShifts;
            m_RequestedShifts = reqShifts;
            m_RequestedAndNotGet = computeDiffBetweenLists(m_RequestedShifts, m_RegisteredShifts);
            m_GetAndNotRequested = computeDiffBetweenLists(m_RegisteredShifts, m_RequestedShifts);
            m_Rank = (((double)m_RegisteredShifts.Count - (double)m_GetAndNotRequested.Count) / (double)(m_RequestedShifts.Count)) * 100;
            SharedData.Instance.GetWorkerById(m_Worker).Rank = m_Rank;
        }

        public void Clean()
        {
            m_Worker = null;
            m_RequestedShifts.Clear();
            m_RegisteredShifts.Clear();
            m_RequestedAndNotGet.Clear();
            m_GetAndNotRequested.Clear();
            m_Rank = 0;
        }

        public bool IsGetShift(Shift shift)
        {
            return m_RegisteredShifts.Contains(shift.Id);
        }
      
        public int GetNumberOfGetAndNotAsked()
        {
            return m_GetAndNotRequested.Count;
        }

        public int GetNumberOfAskedAndNotGet()
        {
            return m_RequestedAndNotGet.Count();
        }

        public double Rank { get { return m_Rank; } }

        public List<string> GetShiftsThatWorkerNotGet()
        {
            return m_RequestedAndNotGet;
        }

        public List<string> GetShiftsThatWorkerGetAndNotRequested()
        {
            return m_GetAndNotRequested;
        }

        public List<string> GetShiftsThatWorkerGet()
        {
            return m_RegisteredShifts;
        }

        public List<string> GetShiftsThatWorkerWanted()
        {
            return m_RequestedShifts;
        }

        public bool IsGotAll()
        {
            return m_RequestedAndNotGet.Count == 0;
        }

        public string Worker { get { return m_Worker; } }

        private List<string> computeDiffBetweenLists(List<string> sourceShiftList, List<string> destShiftList)
        {
            List<string> diffList = new List<string>();
            bool isFound = false;
            foreach (string sourceShift in sourceShiftList)
            {
                isFound = false;
                foreach (string destShift in destShiftList)
                {
                    if (sourceShift.Equals(destShift))
                    {
                        isFound = true;
                    }
                }
                if (!isFound)
                {
                    diffList.Add(sourceShift);
                }
            }
            return diffList;
        }


    }
}
